// components/dropdown/index.js
Component({
  options: {
    multipleSlots: true
  },

  /**
   * 组件的属性列表
   */
  properties: {

    defaultActiveKey: {
      type: String,
      value: ''
    },

    data: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    accordionList: []
  },

  lifetimes: {
    attached() {
      const {
        defaultActiveKey,
        data
      } = this.data;
      const accordionList = data.map(item => {
        if (item.key === defaultActiveKey) {
          return Object.assign({}, item, {
            status: true
          });
        }
        return Object.assign({}, item, {
          status: false
        });
      });
      this.setData({
        accordionList
      });
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleToToggle(event) {
      // 通过 this.data 可以获取到传入的参数
      const {
        accordionList
      } = this.data;
      const {
        index
      } = event.currentTarget.dataset;
      this.setData({
        accordionList: accordionList.map((val, key) => {
          if (key === index) {
            return Object.assign({}, val, {
              status: !val.status
            })
          }
          return val;
        })
      });
    }
  }
})